#ifndef _BASETYPES_H_CSEAPI_
#define _BASETYPES_H_CSEAPI_

#define CSE_MEMORY_ERR             _T("EMemoryError")
#define CSE_SYSTEM_ERR             _T("ESystemError")
#define CSE_ARGS_ERR               _T("EArgsError")
#define CSE_ATTR_ERR               _T("EAttrError")
#define CSE_TYPE_ERR               _T("ETypeError")
#define CSE_TOKEN_ERR              _T("ETokenError")
#define CSE_IO_ERR                 _T("EIoError")
#define CSE_RANGE_ERR              _T("ERangeError")
#define CSE_KEY_ERR                _T("EKeyError")
#define CSE_VALUE_ERR              _T("EValueError")
#define CSE_NOTIMP_ERR             _T("ENotImpError")
#define CSE_SYNTAX_ERR             _T("ESyntaxError")
#define CSE_YIELD_ERR              _T("ECseYield")
#define CSE_RETURN_ERR             _T("ECseReturn")
#define CSE_RUNTIME_ERR            _T("ERuntimeError")
#define CSE_ASSERT_ERR             _T("EAssertError")
#define UNKNOWN_SYS_ERR            _T("EUnknownError")

#define CSE_ARG_NOTMATCH           _T("EArgNotMatch")

#define CSE_BREAK_ERR              _T("ECseBreak")
#define CSE_CONTINUE_ERR           _T("ECseContinue")
#define CSE_ITEREXIT_ERR           _T("EIterExit")

// const of Define Style
#define dsIterCdecl                0
#define dsIterStdcall              1
#define dsIterScript               3
#define dsFrmtScript               7
#define dsPostCdecl                8
#define dsPostStdcall              9

#define LOG_CSE_ERR(errType,errDesc) Cse_LogError(TCseException(errType,errDesc))

#define DECLARE_ONCE_BEGIN         static TBool CurrFuncCalled = false; \
                                   if (! CurrFuncCalled) \
                                   { CurrFuncCalled = true;
#define DECLARE_ONCE_END           }

class CSE_IMPEXP_IN TCseException: public TAbsExcept
{
private:
    CseObj ErrorInfo;

public:
    TCseException(const TCseObj& ErrInfo);
    TCseException(const TCseException& e);
    TCseException(const TCharArray& ErrType, const TCharArray& ErrDesc);
    TCseException(const TCharArray& ErrType, const TCharArray& ErrDesc, const TCseObj& ErrArg);
    ~TCseException(void);

    void setErrArg(const TCseObj& info) const;

    TBool isError(const TCharArray& ErrType) const;
    TCharArray getErrType(void) const;
    TCharArray getErrDesc(void) const;
    TCseObj getErrArg(void) const;

    TCharArray reportStr(void) const;
    TCseObj getErrInfo() const;
};

extern CSE_IMPEXP_IN TCseException Cse_LogError(const TCseException& err);
extern CSE_IMPEXP_IN void Cse_free(CseObj value, TBool recursive);
extern CSE_IMPEXP_IN const TXchar *Cse_GetTypeName(int tp);

class CSE_IMPEXP_IN TStolenObj
{
private:
    CseObj m_obj;

    // disable copy contructor and assignment
#ifdef __VISUALC__
    TStolenObj(const TCseObj& obj);
    TStolenObj(const TStolenObj& obj);
    void operator=(const TCseObj& obj);
    void operator=(const TStolenObj& obj);
    void operator=(CseObj obj);
#endif

public:
    TStolenObj();
    TStolenObj(CseObj obj);
    ~TStolenObj();

    void bind(CseObj obj);

    CseObj operator->() const;
    operator CseObj() const;
};

extern CSE_IMPEXP_IN CseObj CseBltinModule;
extern CSE_IMPEXP_IN CseObj CseMainModule;

extern CSE_IMPEXP_IN CseObj CseEmptySpace;
extern CSE_IMPEXP_IN CseObj CseThreadStacks;
extern CSE_IMPEXP_IN CseObj CseTraceStack;

extern CSE_IMPEXP_IN void Cse_CloseRefCheck(void);
extern CSE_IMPEXP_IN void Cse_HitWhenExit(void);

#endif
